package com.jinandi.app.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.jinandi.app.domain.Authorit;
import com.jinandi.app.domain.Resource;

public interface ResourceDao extends JpaSpecificationExecutor<Resource>, JpaRepository<Resource, Integer> ,PagingAndSortingRepository<Resource, Integer>{

	/**
	 * <根据角色查出出拥有的资源>
	 * @param authorit
	 * @return
	 * @author CGC 
	 * 创建日期:2013-5-9 下午1:37:51
	 */
	@Query("select ar.resource from AuthoritAndRes ar where ar.authorit = ?1")
	List<Resource> findByAuthorit(Authorit authorit);

	/**
	 * <根据ID删除资源>
	 * @param id
	 * @author CGC 
	 * 创建日期:2013-5-9 下午1:37:22
	 */
	@Modifying
	@Transactional
	@Query("delete from Resource where id = ?1")
	void deleteResById(Long id);

	/**
	 * <根据资源ID查询>
	 * @param id
	 * @return
	 * @author CGC 
	 * 创建日期:2013-5-9 下午1:36:44
	 */
	Resource findResById(Long id);
}
